﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Dao.Employee;
using SMTC.Model.TestCore;
using System.Data.Common;
using SMTC.Dao.Role;

namespace SMTC.BO.Employee
{
   public class EmployeeProccessServices
    {
       private EmployeeProccessDao dao = new EmployeeProccessDao();
       private RoleProcessDao pro = new RoleProcessDao();
       public bool InsertEmployee(EmpInfo employee)
       {
           return dao.InsertEmployee(employee);
       }
       public bool UpdateEmployee(EmpInfo employee)
       {
           return dao.UpdateEmployee(employee);
       }
       public bool DeleteEmployee(string userid)
       {
           DbTransaction dbt = null;
           bool operResult = true;

           try
           {
               operResult = operResult && dao.DeleteEmployeebyID(userid,ref dbt);
               operResult = operResult && pro.DELETE_MEMBER_IN_ROLE(userid, ref dbt);

               if (operResult == true)
               {
                   if (dbt != null) dbt.Commit();
                   return true;
               }
               else
               {
                   if (dbt != null) dbt.Rollback();
                   return false;
               }
           }
           catch
           {
               if (dbt != null) dbt.Rollback();
               return false;
           }




         //  return dao.DeleteEmployeebyID(userid);
       }
       public bool Insert_Llist_Employee(List<EmpInfo> list)
       {
           DbTransaction dbt = null;
           try
           {
               foreach (var item in list)
               {
                   if (!dao.Insert_Llist_Employee(item, ref dbt))
                   {
                       throw new Exception("import excel failer");
                   }
                    
               }
               dbt.Commit();
               return true;
           }
           catch (Exception ex)
           {
               if (dbt != null) dbt.Rollback();
               return false;
           }
       }
    }
}
